from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-14 14:02:29.658729
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 14, Jun, 2022
Time: 14:02:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5395
Nobs: 687.000 HQIC: -49.9036
Log likelihood: 8537.49 FPE: 1.68809e-22
AIC: -50.1333 Det(Omega_mle): 1.48222e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.305911 0.058918 5.192 0.000
L1.Burgenland 0.104484 0.038273 2.730 0.006
L1.Kärnten -0.109155 0.020197 -5.405 0.000
L1.Niederösterreich 0.202035 0.079946 2.527 0.011
L1.Oberösterreich 0.111187 0.078328 1.420 0.156
L1.Salzburg 0.256671 0.040849 6.283 0.000
L1.Steiermark 0.047090 0.053447 0.881 0.378
L1.Tirol 0.107582 0.043207 2.490 0.013
L1.Vorarlberg -0.056647 0.037714 -1.502 0.133
L1.Wien 0.035741 0.069501 0.514 0.607
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044922 0.124250 0.362 0.718
L1.Burgenland -0.033762 0.080713 -0.418 0.676
L1.Kärnten 0.040245 0.042592 0.945 0.345
L1.Niederösterreich -0.181291 0.168595 -1.075 0.282
L1.Oberösterreich 0.434236 0.165182 2.629 0.009
L1.Salzburg 0.285657 0.086144 3.316 0.001
L1.Steiermark 0.107674 0.112713 0.955 0.339
L1.Tirol 0.316736 0.091118 3.476 0.001
L1.Vorarlberg 0.027415 0.079533 0.345 0.730
L1.Wien -0.034445 0.146567 -0.235 0.814
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188595 0.030216 6.242 0.000
L1.Burgenland 0.088813 0.019628 4.525 0.000
L1.Kärnten -0.007623 0.010358 -0.736 0.462
L1.Niederösterreich 0.258947 0.041000 6.316 0.000
L1.Oberösterreich 0.139551 0.040170 3.474 0.001
L1.Salzburg 0.045528 0.020949 2.173 0.030
L1.Steiermark 0.024310 0.027410 0.887 0.375
L1.Tirol 0.089756 0.022159 4.051 0.000
L1.Vorarlberg 0.057729 0.019341 2.985 0.003
L1.Wien 0.115532 0.035643 3.241 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110999 0.030565 3.632 0.000
L1.Burgenland 0.043312 0.019855 2.181 0.029
L1.Kärnten -0.013709 0.010478 -1.308 0.191
L1.Niederösterreich 0.186771 0.041474 4.503 0.000
L1.Oberösterreich 0.307951 0.040635 7.579 0.000
L1.Salzburg 0.104505 0.021191 4.931 0.000
L1.Steiermark 0.109180 0.027727 3.938 0.000
L1.Tirol 0.101693 0.022415 4.537 0.000
L1.Vorarlberg 0.068901 0.019565 3.522 0.000
L1.Wien -0.020485 0.036055 -0.568 0.570
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122832 0.056059 2.191 0.028
L1.Burgenland -0.047100 0.036416 -1.293 0.196
L1.Kärnten -0.045966 0.019217 -2.392 0.017
L1.Niederösterreich 0.147297 0.076067 1.936 0.053
L1.Oberösterreich 0.146069 0.074527 1.960 0.050
L1.Salzburg 0.282664 0.038866 7.273 0.000
L1.Steiermark 0.054029 0.050854 1.062 0.288
L1.Tirol 0.168516 0.041111 4.099 0.000
L1.Vorarlberg 0.097797 0.035884 2.725 0.006
L1.Wien 0.076365 0.066128 1.155 0.248
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060894 0.044355 1.373 0.170
L1.Burgenland 0.032115 0.028813 1.115 0.265
L1.Kärnten 0.051352 0.015205 3.377 0.001
L1.Niederösterreich 0.207651 0.060186 3.450 0.001
L1.Oberösterreich 0.299166 0.058967 5.073 0.000
L1.Salzburg 0.043884 0.030752 1.427 0.154
L1.Steiermark 0.008828 0.040237 0.219 0.826
L1.Tirol 0.137287 0.032528 4.221 0.000
L1.Vorarlberg 0.074605 0.028392 2.628 0.009
L1.Wien 0.084851 0.052322 1.622 0.105
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170894 0.053121 3.217 0.001
L1.Burgenland 0.000461 0.034508 0.013 0.989
L1.Kärnten -0.064081 0.018210 -3.519 0.000
L1.Niederösterreich -0.089914 0.072081 -1.247 0.212
L1.Oberösterreich 0.199242 0.070622 2.821 0.005
L1.Salzburg 0.055255 0.036830 1.500 0.134
L1.Steiermark 0.241223 0.048189 5.006 0.000
L1.Tirol 0.499343 0.038956 12.818 0.000
L1.Vorarlberg 0.053422 0.034003 1.571 0.116
L1.Wien -0.063488 0.062663 -1.013 0.311
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.151444 0.060201 2.516 0.012
L1.Burgenland -0.007146 0.039106 -0.183 0.855
L1.Kärnten 0.061946 0.020637 3.002 0.003
L1.Niederösterreich 0.194519 0.081686 2.381 0.017
L1.Oberösterreich -0.080582 0.080033 -1.007 0.314
L1.Salzburg 0.209324 0.041738 5.015 0.000
L1.Steiermark 0.138947 0.054611 2.544 0.011
L1.Tirol 0.069953 0.044148 1.585 0.113
L1.Vorarlberg 0.133810 0.038535 3.472 0.001
L1.Wien 0.130480 0.071013 1.837 0.066
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374458 0.035000 10.699 0.000
L1.Burgenland 0.001676 0.022736 0.074 0.941
L1.Kärnten -0.022596 0.011998 -1.883 0.060
L1.Niederösterreich 0.216695 0.047492 4.563 0.000
L1.Oberösterreich 0.209557 0.046530 4.504 0.000
L1.Salzburg 0.042489 0.024266 1.751 0.080
L1.Steiermark -0.017268 0.031750 -0.544 0.587
L1.Tirol 0.102836 0.025667 4.007 0.000
L1.Vorarlberg 0.064849 0.022404 2.895 0.004
L1.Wien 0.029292 0.041287 0.709 0.478
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037234 0.129578 0.187737 0.149915 0.110768 0.089515 0.053827 0.213922
Kärnten 0.037234 1.000000 -0.017375 0.133125 0.053588 0.092204 0.439165 -0.057180 0.094159
Niederösterreich 0.129578 -0.017375 1.000000 0.333343 0.138466 0.291955 0.081355 0.173361 0.311210
Oberösterreich 0.187737 0.133125 0.333343 1.000000 0.224420 0.317634 0.167865 0.156919 0.260892
Salzburg 0.149915 0.053588 0.138466 0.224420 1.000000 0.135947 0.105307 0.128680 0.135130
Steiermark 0.110768 0.092204 0.291955 0.317634 0.135947 1.000000 0.140190 0.124022 0.066629
Tirol 0.089515 0.439165 0.081355 0.167865 0.105307 0.140190 1.000000 0.091589 0.143519
Vorarlberg 0.053827 -0.057180 0.173361 0.156919 0.128680 0.124022 0.091589 1.000000 0.012133
Wien 0.213922 0.094159 0.311210 0.260892 0.135130 0.066629 0.143519 0.012133 1.000000